package com.solcoo.interceptor;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class ExceptionInterceptor extends HandlerInterceptorAdapter {

	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) throws Exception {
		if (ex != null) {			
			response.setCharacterEncoding("UTF-8");  
		    response.setContentType("application/json; charset=utf-8");  
		
		    PrintWriter out = response.getWriter();
		    
		    out.append("{\"result\":false,\"failMsg\":\"系统异常，请重试\"}");
		    
		    out.close();
		} else {
			super.afterCompletion(request, response, handler, ex);
		}
	}

}
